#include<bits/stdc++.h>
using namespace std;
int a[10000];
void an(){

    int n;

    cin >> n;

    for(int i = 1; i <= n; i++){

        cin>> a[i];

    }
    cout <<(a[1]+a[2]+2792)%1000<<endl;

}

int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);

    int t;
    cin>>t;
    while(t--){

        an();

    }

    return 0;

}
